<template>
  <div>
    <van-nav-bar
  title="添加地址"

  left-arrow
  @click-left="back"
/>
<van-address-edit
  :area-list="areaList"
  :show-postal="false"
  :show-delete="false"
  show-set-default
  show-search-result
  :search-result="searchResult"
  :area-columns-placeholder="['请选择', '请选择', '请选择']"
  @save="onSave"
  @delete="onDelete"
  @change-detail="onChangeDetail"
/>
<button @click="onSave">'casoicjc'</button>
  </div>
</template>

<script>

import { Toast } from 'vant'
import { areaList } from '@vant/area-data'
import { addAddress } from '@/api/pay'

export default {
  data () {
    return {
      areaList,
      searchResult: []
    }
  },
  methods: {
    async onSave (content) {
      console.log(content)
      // 准备请求数据
      const data = {
        form: {
          name: content.name,
          phone: content.tel,
          region: [
            {
              value: 782,
              label: content.province
            },
            {
              value: 783,
              label: content.city
            },
            {
              value: 785,
              label: content.county
            }
          ],
          detail: content.addressDetail
        }
      }
      //   调用接口发送请求
      const res = await addAddress(data)
      console.log(res)
      this.$router.back()
    },
    onDelete () {
      Toast('delete')
    },
    onChangeDetail (val) {
      if (val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区'
          }
        ]
      } else {
        this.searchResult = []
      }
    },
    back () {
      this.$router.back()
    }
  }
}
</script>

<style>

</style>
